﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCWeb.Models; // this is required...

namespace MVCWeb.Controllers
{
    public class WebmasterController : Controller
    {

        /// <summary>
        /// ////////////////
        /// </summary>
        /// <returns></returns>
        /// 
        public ActionResult OutOfStockDetail()
        {
            List<TvModelPrtials> plist = WebMasterClientServices.OutOfStockDetail();///TvClientService.OutOfStockDetail();

            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            int totalCustomers = WebMasterClientServices.GetTotalUser();
            int totalWebmasters = WebMasterClientServices.GetTotalWebMaster();
            int totalBlockedUsers = WebMasterClientServices.GetTotalBlockUser();
            int numofoutofstock = TvClientService.GetNumberOfOutOfStock();
            ViewData["webmasterPartial"] = "<b>Statistics Information</b>" + "<br />";
            ViewData["webmasterPartial"] += "Total Customers: " + totalCustomers + " " + "<a href='" + url.Action("Index", "Webmaster") + "'>Customer List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Webmasters: " + totalWebmasters + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeWebMaster", "Webmaster") + "'>Webmaster List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Users Blocked: " + totalBlockedUsers + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeBlockUser", "Webmaster") + "'>Block List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Popular Item List " + "<a href='" + url.Action("GetTopFive", "Webmaster") + "'>Check Popular Items </a>" + "<br />";
            ViewData["webmasterPartial"] += "Sold Out Item List: " + "(" + numofoutofstock + ")" + "<a href='" + url.Action("OutOfStockDetail", "Webmaster") + "'>Sold Out</a>" + "<br />";
            
            return View("OutOfStockDetail", plist);

        }

        public ActionResult GetTopFive()
        {
            List<TvModelPrtials> plist = WebMasterClientServices.GetTopFive();
            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            int totalCustomers = WebMasterClientServices.GetTotalUser();
            int totalWebmasters = WebMasterClientServices.GetTotalWebMaster();
            int totalBlockedUsers = WebMasterClientServices.GetTotalBlockUser();
            int numofoutofstock = TvClientService.GetNumberOfOutOfStock();
            ViewData["webmasterPartial"] = "<b>Statistics Information</b>" + "<br />";
            ViewData["webmasterPartial"] += "Total Customers: " + totalCustomers + " " + "<a href='" + url.Action("Index", "Webmaster") + "'>Customer List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Webmasters: " + totalWebmasters + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeWebMaster", "Webmaster") + "'>Webmaster List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Users Blocked: " + totalBlockedUsers + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeBlockUser", "Webmaster") + "'>Block List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Popular Item List " + "<a href='" + url.Action("GetTopFive", "Webmaster") + "'>Check Popular Items </a>" + "<br />";
            ViewData["webmasterPartial"] += "Sold Out Item List: " + "(" + numofoutofstock + ")" + "<a href='" + url.Action("OutOfStockDetail", "Webmaster") + "'>Sold Out</a>" + "<br />";
            return View("GetTopFive", plist);

        }

      

        ///////////////////////

        public ActionResult Index() 
        {
            List<CustomerModel> clist = CustomerClientServices.GetName();
            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            int totalCustomers = WebMasterClientServices.GetTotalUser();
            int totalWebmasters = WebMasterClientServices.GetTotalWebMaster();
            int totalBlockedUsers = WebMasterClientServices.GetTotalBlockUser();
            int numofoutofstock = TvClientService.GetNumberOfOutOfStock();
            ViewData["webmasterPartial"] = "<b>Statistics Information</b>" + "<br />";
            ViewData["webmasterPartial"] += "Total Customers: " + totalCustomers + " " + "<a href='" + url.Action("Index", "Webmaster") + "'>Customer List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Webmasters: " + totalWebmasters + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeWebMaster", "Webmaster") + "'>Webmaster List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Users Blocked: " + totalBlockedUsers + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeBlockUser", "Webmaster") + "'>Block List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Popular Item List " + "<a href='" + url.Action("GetTopFive", "Webmaster") + "'>Check Popular Items </a>" + "<br />";
            ViewData["webmasterPartial"] += "Sold Out Item List: " + "(" + numofoutofstock + ")" + "<a href='" + url.Action("OutOfStockDetail", "Webmaster") + "'>Sold Out</a>" + "<br />";
                
            return View("Index" , clist);
        }

        public ActionResult ShowMeWebMaster()
        {
            List<WebmasterModel> wlist = new List<WebmasterModel>();
            wlist = WebMasterClientServices.GetWebMasterInfor();
            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            int totalCustomers = WebMasterClientServices.GetTotalUser();
            int totalWebmasters = WebMasterClientServices.GetTotalWebMaster();
            int totalBlockedUsers = WebMasterClientServices.GetTotalBlockUser();
            int numofoutofstock = TvClientService.GetNumberOfOutOfStock();
            ViewData["webmasterPartial"] = "<b>Statistics Information</b>" + "<br />";
            ViewData["webmasterPartial"] += "Total Customers: " + totalCustomers + " " + "<a href='" + url.Action("Index", "Webmaster") + "'>Customer List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Webmasters: " + totalWebmasters + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeWebMaster", "Webmaster") + "'>Webmaster List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Users Blocked: " + totalBlockedUsers + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeBlockUser", "Webmaster") + "'>Block List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Popular Item List " + "<a href='" + url.Action("GetTopFive", "Webmaster") + "'>Check Popular Items </a>" + "<br />";
            ViewData["webmasterPartial"] += "Sold Out Item List: " + "(" + numofoutofstock + ")" + "<a href='" + url.Action("OutOfStockDetail", "Webmaster") + "'>Sold Out</a>" + "<br />";
            return View("ShowMeWebMaster", wlist);
        }

        public ActionResult ShowMeBlockUser()
        {
            List<WebmasterModel> wlist = WebMasterClientServices.GetBlockUserInfor();
            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            int totalCustomers = WebMasterClientServices.GetTotalUser();
            int totalWebmasters = WebMasterClientServices.GetTotalWebMaster();
            int totalBlockedUsers = WebMasterClientServices.GetTotalBlockUser();
            int numofoutofstock = TvClientService.GetNumberOfOutOfStock();
            ViewData["webmasterPartial"] = "<b>Statistics Information</b>" + "<br />";
            ViewData["webmasterPartial"] += "Total Customers: " + totalCustomers + " " + "<a href='" + url.Action("Index", "Webmaster") + "'>Customer List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Webmasters: " + totalWebmasters + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeWebMaster", "Webmaster") + "'>Webmaster List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Total Users Blocked: " + totalBlockedUsers + "/" + totalCustomers + " " + "<a href='" + url.Action("ShowMeBlockUser", "Webmaster") + "'>Block List</a>" + "<br />";
            ViewData["webmasterPartial"] += "Popular Item List " + "<a href='" + url.Action("GetTopFive", "Webmaster") + "'>Check Popular Items </a>" + "<br />";
            ViewData["webmasterPartial"] += "Sold Out Item List: " + "(" + numofoutofstock + ")" + "<a href='" + url.Action("OutOfStockDetail", "Webmaster") + "'>Sold Out</a>" + "<br />";
            if (wlist == null) 
            {
                return View("ShowNoBlockUser");
            }


            return View("ShowMeBlockUser", wlist);
        }

        public ActionResult testm() 
        {
            List<TvModelPrtial> plist = TvClientService.OutOfStockDetail();


            return View("OutOfStockDetail");
        
        }


        
 
        public ActionResult BlockUser(int id) 
        {
            try
            {
                WebMasterClientServices.BlockUser(id);
                return RedirectToAction("Index"); // maybe we need to change Direct tion
                // like webmaster page. I guess index will be webmaster page
            }
            catch
            {
                return View();
            }
        }



        public ActionResult UnblockUser(int id)
        {
            try
            {
                WebMasterClientServices.UnblockUser(id);
                return RedirectToAction("Index");
            }
            catch 
            {
                return View();
            }
        }

        public ActionResult ChangePermission(CustomerModel UserObj)
        {
            try
            {
                UserObj.permission = 1;
                WebMasterClientServices.ChangePermission(UserObj);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        // neeed to change way to display result 
        // TODO 1. change the way to display result.
        //      2.  change the direction
        public ActionResult GetCustomerDetails(int id) 
        {
            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            ViewData["breadCrumbData"] = "<a href='" + url.Action("Index", "Customer") + "'>Customer List</a>";
            ViewData["breadCrumbData"] += " > Details";

            CustomerModel DetailOfCustomer = CustomerClientServices.GetCustomerDetails(id);

            return View("Details", DetailOfCustomer);
        }


        public ActionResult DeleteCustomer(int id) 
        {
            try
            {
                WebMasterClientServices.DeleteCustomer(id);
                return RedirectToAction("Index");
            }
            catch 
            {
                return View();
            }
        }

        
        
        
        public ActionResult WebMasterPage()
        {
           int totaluser =  WebMasterClientServices.GetTotalUser();
           int totalwebmaster = WebMasterClientServices.GetTotalWebMaster();
           int totalblockuser = WebMasterClientServices.GetTotalBlockUser();
           
           int numofoutofstock = TvClientService.GetNumberOfOutOfStock();

           String TotalUser = Convert.ToString(totaluser);
           String totalweb = Convert.ToString(totalwebmaster);
           String totalblock = Convert.ToString(totalblockuser);
           String numout = Convert.ToString(numofoutofstock);
 
            ViewData["TotalUser"] = TotalUser;
            ViewData["TotalWeb"] = totalweb;
            ViewData["TotalBlock"] = totalblock;
            ViewData["Outofstock"] = numout;


            return View();
        }
      



        public ActionResult About()
        {
            return View();
        }

        public ActionResult Home() 
        {
            return View();
        }


    }
}
